package org.nf.servlet;

import org.nf.demo.entity.SumUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author czl
 * @Date 2024-04-24
 */
@WebServlet("/getSum")
public class GetSumServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 调用 project-cc 的方法，计算两数之和
        int r = new SumUtil().sum(1, 1);

        // 把数据放在作用域对象中
        req.setAttribute("r",r);

        // 转发页面
        req.getRequestDispatcher("showdata.jsp").forward(req,resp);
    }
}
